<?php
$montos = array();
$montos["10000"] = '$10,000.00 MXN';
$montos["20000"] = '$20,000.00 MXN';
$montos["30000"] = '$30,000.00 MXN';
$montos["40000"] = '$40,000.00 MXN';
$montos["50000"] = '$50,000.00 MXN';
$montos["60000"] = '$60,000.00 MXN';
$montos["70000"] = '$70,000.00 MXN';
$montos["80000"] = '$80,000.00 MXN';
$montos["90000"] = '$90,000.00 MXN';
$plazos = array();
$plazos[12] = '12 meses';
$plazos[24] = '24 meses';
$ahorros = array();
$ahorros[100] = '$100.00 MXN';
$ahorros[200] = '$200.00 MXN';
$ahorros[300] = '$300.00 MXN';
$ahorros[400] = '$400.00 MXN';
$ahorros[500] = '$500.00 MXN';

function _e($data, $name)
{
    $value = null;
    if ($data !== null)
    {
        $value = $data[$name];
    }
    echo $value;
}

function _o($array, $data, $name)
{
    if ($data !== null)
    {
        $value = $data[$name];
        foreach ($array as $key => $v)
        {
            if (strcmp($value, (string) $key) == 0)
            {
                echo '<option value="' . $key . '" selected="selected">' . $v . '</option>' . PHP_EOL;
            }
            else
            {
                echo '<option value="' . $key . '">' . $v . '</option>' . PHP_EOL;
            }
        }
    }
    else
    {
        foreach ($array as $key => $value)
        {
            echo '<option value="' . $key . '">' . $value . '</option>' . PHP_EOL;
        }
    }
}
?>
<?php if (is_string($success) === true): ?>
    <div class="alert alert-danger">
        <?php echo $success; ?>
    </div>
<?php endif; ?>
<?php if ($success === true): ?>
    <div class="alert alert-success">
        El crédito fue creado correctamente.
    </div>
<?php endif; ?>
<form role="form" method="post" action="<?php
echo $this->Html->url(array(
    'action' => 'creditoNuevo'));
?>">
    <div class="form-group">
        <label for="rfc">R.F.C. (sin homoclave. E.j.: <i>XXXX999999</i>)</label>
        <input type="text" name="rfc" class="form-control" id="rfc" placeholder="R.F.C." required="required" value="<?php _e($data, 'rfc'); ?>">
    </div>
    <div class="form-group">
        <label for="folio">Folio</label>
        <input type="text" name="folio" class="form-control" id="folio" placeholder="Folio" required="required" value="<?php _e($data, 'folio'); ?>">
    </div>
    <div class="form-group">
        <label for="delegacion">Delegación</label>
        <input type="text" name="delegacion" class="form-control" id="delegacion" placeholder="Delegación" required="required" value="<?php _e($data, 'delegacion'); ?>">
    </div>
    <div class="form-group">
        <label for="nombre">Nombre(s)</label>
        <input type="text" name="nombre" class="form-control" id="nombre" placeholder="Nombre(s)" required="required" value="<?php _e($data, 'nombre'); ?>">
    </div>
    <div class="form-group">
        <label for="paterno">Apellido paterno</label>
        <input type="text" name="paterno" class="form-control" id="paterno" placeholder="Apellido paterno" required="required" value="<?php _e($data, 'paterno'); ?>">
    </div>
    <div class="form-group">
        <label for="materno">Apellido materno</label>
        <input type="text" name="materno" class="form-control" id="materno" placeholder="Apellido materno" required="required" value="<?php _e($data, 'materno'); ?>">
    </div>
    <div class="form-group">
        <label for="cuenta">Cuenta bancaria</label>
        <input type="text" name="cuenta" class="form-control" id="cuenta" placeholder="Cuenta bancaria" required="required" value="<?php _e($data, 'cuenta'); ?>">
    </div>
    <div class="form-group">
        <label for="monto">Monto del crédito</label>
        <select class="form-control" name="monto">
            <?php _o($montos, $data, 'monto'); ?>
        </select>
    </div>
    <div class="form-group">
        <label for="plazo">Plazo</label>
        <select class="form-control" name="plazo">
            <?php _o($plazos, $data, 'plazo'); ?>
        </select>
    </div>
    <div class="form-group">
        <label for="pagoMensual">Pago mensual</label>
        <input type="text" name="pagoMensual" class="form-control" id="pagoMensual" placeholder="Pago mensual" required="required" value="<?php _e($data, 'pagoMensual'); ?>">
    </div>
    <div class="form-group">
        <label for="totalPago">Monto total de pago</label> 
        <input type="text" name="totalPago" class="form-control" id="totalPago" placeholder="Monto total de pago" required="required" value="<?php _e($data, 'totalPago'); ?>">
    </div>
    <div class="form-group">
        <label for="ahorro">Ahorro</label>
        <select class="form-control" name="ahorro">
            <?php _o($ahorros, $data, 'ahorro'); ?>
        </select>
    </div>
    <div class="form-group">
        <label for="interes">Interés mensual</label>
        <input type="text" name="interes" class="form-control" id="interes" placeholder="Interés mensual" required="required" value="1" value="<?php _e($data, 'interes'); ?>">
    </div>
    <div class="form-group">
        <label for="instrumento">Instrumento</label>
        <input type="text" name="instrumento" class="form-control" id="instrumento" placeholder="Instrumento" required="required" value="<?php _e($data, 'instrumento'); ?>">
    </div>
    <div class="form-group">
        <label for="fechaInstrumento">Fecha instrumento(yyyy-mm-dd)</label>
        <input type="text" name="fechaInstrumento" class="form-control" id="fechaInstrumento" placeholder="Fecha instrumento" required="required" value="<?php _e($data, 'fechaInstrumento'); ?>">
    </div>
    <button type="submit" class="btn btn-warning">Agregar crédito</button>
</form>
